<template>
	<view>
		<cu-custom :isBack="true" bgColor="bg-white">
			<block slot="backText"></block>
			<block slot="content"><text>待收益积分释放</text></block>
		</cu-custom>
		
		<view class="whole-box" style="background-image: url(https://pingtuan-1251091607.cos.ap-shanghai.myqcloud.com/images/2021/03/10/image_1615357505_aCuJdqd0.png);background-size: 100% 100%;">
			
			<view class="gold-black-box">
				<view class="top-box" style="height: 130px;">
					<!-- <image class="top-box-bg" src="@/static/black_bg/stander-box.png" mode="aspectFill"></image> -->
					<view class="top-box-content">
						<view class="top-left-box">
							<view class="title">待收益积分释放规则</view>
							<view class="current-t">1:1张熊宝宝可释放{{this.coupon_wait_set}}待收益积分</view>
							<view class="current-t">2:1张开团券可释放{{this.chief_wait_set}}待收益积分</view>
							
						</view>
						<!-- <image class="icon-gold-tixian" src="@/static/icon-gold-money.png" mode="aspectFill"></image> -->
					</view>
				</view>
			</view>
			<view class="gold-black-box">
				<view class="top-box" style="height: 900rpx;">
					<!-- <image class="top-box-bg" src="@/static/black_bg/stander-box.png" mode="aspectFill"></image> -->
					<view class="top-box-content">
						<view class="top-left-box">
							<view class="title">待收益积分兑换</view>
							<view class="current-num">当前积分数量：<text>{{statistics && statistics.user_integral > 0 ? statistics.user_integral : 0}}</text></view>
							<view class="current-num">当前待收益积分数量：<text>{{statistics && statistics.wait_integral > 0 ? statistics.wait_integral : 0}}</text></view>
							<view class="current-num">当前熊宝宝数量：<text>{{statistics && statistics.money_coupon > 0 ? statistics.money_coupon : 0}}</text></view>
							<view class="current-num">当前开团券数量：<text>{{statistics && statistics.chief_coupon > 0 ? statistics.chief_coupon : 0}}</text></view>
							<view class="input-box">
								<input class="y-cou" type="number" placeholder="请输入熊宝宝数量" placeholder-class="my-input-holder" v-model="formData.money_coupon" @input="onInput"/>
								<text class="y-cou-text">(请输入熊宝宝数量)</text>
								<text style="border: 1px solid #FFDE1E;width: 30rpx;text-align: center;" @click="del('money_coupon')">-</text>
								<input style="width: 50rpx;margin-left: 0;" type="number" placeholder="请输入熊宝宝数量" placeholder-class="my-input-holder" v-model="formData.money_coupon" @input="onInput"/>
								<text style="background-color: #FFDE1E;width: 30rpx;text-align: center;" @click="add('money_coupon')">+</text>
							</view>
							<view class="input-box">
								<input class="y-cou" type="number" placeholder="请输入开团券数量" placeholder-class="my-input-holder" v-model="formData.chief_coupon" @input="onInput"/>
								<text class="y-cou-text">(请输入开团券数量)</text>
								<text style="border: 1px solid #FFDE1E;width: 30rpx;text-align: center;" @click="del('chief_coupon')">-</text>
								<input style="width: 50rpx;margin-left: 0;" type="number" placeholder="请输入开团券数量" placeholder-class="my-input-holder" v-model="formData.chief_coupon" @input="onInput"/>
								<text style="background-color: #FFDE1E;width: 30rpx;text-align: center;" @click="add('chief_coupon')">+</text>
								
							</view>
							<view class="input-box">
								<text>可兑换积分:</text>
								<input type="number" placeholder="可兑换积分" placeholder-class="my-input-holder" disabled="true" v-model="intall" />
							</view>
							<view class="integral-btn">
								<!-- <text class="note">积分:</text>
								<text class="note-num">{{integral}}</text> -->
								<text class="btn" @tap="onSubmit">确认兑换</text>
							</view>
						</view>
						<!-- <image class="icon-gold-tixian" src="@/static/icon-gold-money.png" mode="aspectFill"></image> -->
					</view>
				</view>
				
				
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		computed: mapState(['forcedLogin', 'hasLogin', 'channelLogin']),
		mounted() {
			this.getScrollH()
		},
		data() {
			return {
				statistics: null,
				member:null,
				loading: false,
				scrollHeight: 600,
				integral:0,
				formData:{
					money_coupon:1,
					chief_coupon:1,
					
				},
				coupon_wait_set:0,
				chief_wait_set:0,
				money_roll_to_intergal:1,
				list: [],
				hasMore: true,
				page: 1,
				intall:0,
				
			}
		},
		onLoad() {
		},
		onShow() {
			if (this.$common.loginAuth(true)) {
				// this.$nextTick((r) => {
				// 	uni.startPullDownRefresh({})
				// })
				this.$common.getMember().then((member)=>{
					this.member = member
					this.getTotal();
					
					// this.getList()
				})
			}
		},
		methods: {
			del(type) {
				if (type == 'money_coupon') {
					if (this.formData.money_coupon > 1) {
						this.formData.money_coupon = this.formData.money_coupon - 1;
					}
					
				} else {
					if (this.formData.chief_coupon > 1) {
						this.formData.chief_coupon = this.formData.chief_coupon - 1;
					}
				}
				this.getAll()
				
			},
			add(type) {
				
				if (type == 'money_coupon') {
					this.formData.money_coupon = this.formData.money_coupon + 1;
				} else {
					
					this.formData.chief_coupon = this.formData.chief_coupon + 1;
				}
				this.getAll()
				
			},
			getAll(){
				this.intall = parseFloat(this.formData.money_coupon * this.coupon_wait_set) + parseFloat(this.chief_wait_set * this.formData.chief_coupon)
			},
			getTotal() {
				this.$http
					.get('integral_info', {})
					.then((response) => {
						this.statistics = response.data.data
						this.money_roll_to_intergal = response.data.data.channel_con.money_roll_to_intergal
						this.coupon_wait_set = response.data.data.channel_con.coupon_wait_set
						this.chief_wait_set = response.data.data.channel_con.chief_wait_set
						this.getAll()
					})
					.catch((response) => {
						console.log(response)
					})
			},
			getScrollH() {
				let sys = uni.getSystemInfoSync();
				let winHeight = sys.windowHeight;
				//console.log(winHeight)
				let _this = this
				// 计算scroll-view高度
				let query = uni.createSelectorQuery().in(_this);
				query.select('.top-box').boundingClientRect()
				query.selectViewport()
				query.exec(function(res) {
					//console.log(res)
					_this.scrollHeight = winHeight - res[0].bottom - 10 - 24
					
				})
			},
			onInput(e) {
				// 【不用v-model绑定表单,直接时间获取值】这种方式是uni-app官方的方式,测试结果正确！
				console.log(e.detail)
				// this.formData.coupon = e.detail.value
				// this.integral = e.detail.value * this.money_roll_to_intergal
				this.getAll()
			},
			onSubmit(){
				let formData = this.formData
				// if (formData.money_coupon <= 0) {
				// 	this.$common.showError('请输要兑换的熊宝宝')
				// 	return
				// }
				if (formData.chief_coupon <= 0 && formData.money_coupon <= 0) {
					this.$common.showError('请输要兑换的一种券')
					return
				}
				console.log(this.statistics.wait_integral)
				if (this.statistics.wait_integral < this.intall) {
					this.$common.showError('待收益积分不足')
					return
				}
				
				uni.showLoading({
					title: '处理中'
				})
				this.$http.post('wait_integral', formData).then((response) => {
				uni.hideLoading()
				if (response.data.data.status == 200) {
					this.$common.showSuccess('兑换成功')
					this.getTotal()
				}
				}).catch((response) => {
					uni.hideLoading()
				this.checkLoading = false
				})
			},
			
			// onReachBottom() {
			// 	this.getList()
			// },
			onPullDownRefresh() {
				this.getTotal()
				
			},

		},
	}
</script>


<style>
	.y-cou-text{
		font-size: 12px!important;
		margin-right: 5px!important;
	}
	.y-cou{
		width: 220rpx!important;
		margin-left: 0!important;
	}
	.whole-box{
		background-color: #333333;
		min-height: calc(100vh - 45px - 50rpx);
		padding: 25rpx 0;
	}
	.gold-black-box{
		padding: 25rpx 0;
		margin: 0 10rpx;
		/* border: 2rpx solid #999999; */
		border-radius: 30rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	
	.gold-black-box .top-box{
		/* margin-top: 25rpx; */
		width: 690rpx;
		height: 400rpx;
		/* border: 2rpx solid #999999; */
		border-radius: 30rpx;
		overflow: hidden;
		position: relative;
		background-color: #FEFCEA;
	}
	.top-box .top-box-bg{
		width: 100%;
		height: 100%;
	}
	.top-box .top-box-content{
		width: 690rpx;
		/* height: 276rpx; */
		position: absolute;
		left: 0;
		top: 0;
		display: flex;
		justify-content: space-between;
		/* align-items: center; */
		margin-top: 30rpx;
		padding: 0 50rpx;
	}
	.top-box-content .top-left-box{
		flex: 1;
	}
	.top-left-box .title{
		font-size: 34rpx;
		font-weight: bold;
		color: #6C5E0B;
		text-align: center;
	}
	.top-left-box .current-t{
		margin-top: 20rpx;
		font-size: 26rpx;
		color: #6C5E0B;
		text-align: center;
	}
	.top-left-box .current-num{
		margin-top: 30rpx;
		font-size: 30rpx;
		font-weight: bold;
		color: #000000;
	}
	.top-left-box .current-num text{
		margin-left: 10rpx;
		font-size: 38rpx;
		font-weight: bold;
		color: #000000;
	}
	.top-left-box .input-box{
		padding: 16rpx 0;
		display: flex;
		align-items: center;
		/* border-bottom: 1rpx solid #999999; */
		margin-top: 10rpx;
	}
	.top-left-box .input-box text{
		font-size: 28rpx;
		font-weight: bold;
		color: #000000;
	}
	.top-left-box .input-box input{
		margin-left: 15rpx;
		background: #ffffff;
		border-radius: 10rpx;
		width: 350rpx;
		height: 60rpx;
		text-align: center;
		line-height: 38rpx;
		font-size: 24rpx;
		color: #000000;
	}
	.my-input-holder{
		font-size: 24rpx;
		color: #000000;
	}
	.top-left-box .integral-btn{
		margin-top: 30rpx;
		display: flex;
		align-items: center;
	}
	.integral-btn .note{
		font-size: 30rpx;
		font-weight: bold;
		color: #000000;
	}
	.integral-btn .note-num{
		width: 140rpx;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
		background: #ffffff;
		border-radius: 10rpx;
		font-size: 18rpx;
		font-weight: bold;
		color: #000000;
		margin-left: 15rpx;
	}
	.integral-btn .btn{
		width: 240rpx;
		height: 58rpx;
		text-align: center;
		line-height: 58rpx;
		background: #FFE84C;
		/* box-shadow: 0px 2px 0px 0px rgba(91, 82, 67, 0.5); */
		border-radius: 10rpx;
		font-size: 18rpx;
		font-weight: bold;
		color: #000000;
		/* margin-left: 90rpx; */
		margin: 0 auto;
	}
	
	.top-box-content .icon-gold-tixian{
		width: 130rpx;
		height: 106rpx;
		flex-shrink: 0;
		margin-left: 20rpx;
	}
</style>

<style>
	.gold-black-box .list{
		margin-top: 10px;
	}
	.list .my-data-box{
		margin-top: 20rpx;
		width: 690rpx;
		height: 160rpx;
		/* border: 2rpx solid #999999; */
		border-radius: 30rpx;
		overflow: hidden;
		position: relative;
		background-color: #FFF5C9;
	}
	.list .my-data-box:first-child{
		margin-top: 0;
	}
	.my-data-box .my-data-box-bg{
		width: 100%;
		height: 100%;
	}
	.my-data-box .my-data-box-content{
		width: 690rpx;
		height: 160rpx;
		position: absolute;
		left: 0;
		top: 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 40rpx;
	}

	.my-data-box-content .left-box{
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: space-between;
	}
	.left-box .title{
		width: 	500rpx;
		font-size: 34rpx;
		font-weight: bold;
		color: #000000;
		overflow: hidden;    
		text-overflow:ellipsis;    
		white-space: nowrap;
	}
	.left-box .time{
		margin-top: 16rpx;
		font-size: 34rpx;
		color: #000000;
	}
	.my-data-box-content .num{
		margin-left: 10rpx;
		font-size: 40rpx;
		font-weight: bold;
		color: #000000;
	}
	.my-data-box-content .num.up{
		color: #2A6843;
	}
	.item .num.down{
		color: #A21818;
	}
</style>